package com.mobile.handle;
import java.util.ArrayList;
import java.util.List;

import android.os.Handler;
import android.os.Message;
import android.util.Log;

public class Hand extends Handler
{
	public final static String TAG = "Hand";
	
    private static Hand hand;

    public List<HandEventListen> handEventListen;

    private Hand()
    {
        handEventListen = new ArrayList<HandEventListen>();
    }

    public static Hand getHand()
    {
        if(hand == null) hand = new Hand();
        return hand;
    }

    public void handleMessage(Message msg)
    {
        if(handEventListen != null)
        {
            for(int i = 0;i < handEventListen.size(); i++)
               handEventListen.get(i).handleMessage(msg);
        }
        super.handleMessage(msg);
    }
    
    public List<HandEventListen> getHandEventListen()
    {
        return handEventListen;
    }

    public void setHandEventListen(HandEventListen Listen)
    {
        if(handEventListen.size()==0)
        {
            handEventListen.add(Listen);
        }
        else
        {
//            for(int i=0;i < handEventListen.size(); i++)
//            {
//            	if(Listen.getClass().equals(handEventListen.get(i).getClass()))
//            	{
//            		handEventListen.remove(i);
//            	}
//            	else
//            	{
//            		continue;
//            	}
//            }
        	handEventListen.clear();
            handEventListen.add(Listen);
        }
    }
    
    public void delectListener(HandEventListen Listen)
    {
    	for(int i = 0;i < handEventListen.size(); i++)
        {
            if(Listen.equals(handEventListen.get(i)))
            {
                handEventListen.remove(i);
                Log.v(TAG, "name = " + Listen.getClass().getSimpleName());
            }
        } 
    }
}
